package com.sogoodsoft.service.crm;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.sogoodsoft.dao.common.CommonHibernateDao;
import com.sogoodsoft.dao.crm.CustomerDao;
import com.sogoodsoft.entity.account.User;
import com.sogoodsoft.entity.crm.Customer;
import com.sogoodsoft.service.account.AccountManager;
import com.sogoodsoft.service.common.AbstractService;

@Component
@Transactional
public class CustomerService extends AbstractService<Customer,Long> {

    @Autowired
    private CustomerDao customerDao;
    
    @Autowired
    private AccountManager accountManager;

    @SuppressWarnings({ "unchecked", "rawtypes" })   
    @Override   
    public CommonHibernateDao getDao() {
        return customerDao;
    }
    
    public void dispatch(Long userid,String customers){
    	String hql = "from Customer c where c.id in("+customers+")";
    	logger.debug(hql);
    	User user = accountManager.getUser(userid);
    	List<Customer> list = customerDao.find(hql);
    	for(Customer cus:list){
    		cus.setBelong(userid);
    		cus.setUsername(user.getName());
    		logger.debug(cus.getLinkman());
    		customerDao.save(cus);
    	}
    }

}

